#!/bin/bash

set -e

rm -rf bin
mkdir bin
rm -rf tmp
mkdir tmp

cleanup_exit() {
  echo "Test failed"
  exit ${1}
}

echo "Build should succeed"
../../build.py build ... > tmp/tmp_file1 2>&1 || cleanup_exit 1

touch main.cc
grep 'Finished building //:test1' tmp/tmp_file1 || cleanup_exit 1
grep 'Finished building //:test2' tmp/tmp_file1 || cleanup_exit 1


echo "Build should succeed"
../../build.py build ... > tmp/tmp_file2 2>&1 || cleanup_exit 1

grep 'Finished building //:test1' tmp/tmp_file2 || cleanup_exit 1
grep 'Finished building //:test2' tmp/tmp_file2 || cleanup_exit 1

rm -rf bin tmp

echo 'Test passed'
